package com.ars.order;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.VBox;

import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.ResourceBundle;

public class QueryResultController implements Initializable {
    @FXML
    private VBox contentBox;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        ArrayList<Integer> fids = (ArrayList<Integer>) resources.getObject("Fids");

        for (int i = 0; i < fids.size(); i++) {
            int fid = fids.get(i);
            try {
                FXMLLoader loader = new FXMLLoader(getClass().getResource("OneResult.fxml"));
                loader.setResources(new ResourceBundle() {
                    @Override
                    protected Object handleGetObject(String key) {
                        if (key.equals("fid")) {
                            return fid;
                        }
                        return null;
                    }

                    @Override
                    public Enumeration<String> getKeys() {
                        return null;
                    }
                });
                contentBox.getChildren().add(loader.load());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
